// pages/kaitong/kaitong.js
let WxParse = require('../../wxParse/wxParse.js');
const util = require("../../utils/util.js");
const app = getApp()
const baseImgUrl = util.baseImgUrl;
const jumpurl = util.jumpurl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbar:[{
          tag:0,
          name:"在线开通"
      },{
          tag: 0,
          name: "会员码开通"
      }],
    activeIndex:0,//默认选中在线开通
    activeIndex2:0,//默认选择第一个套餐
    vipPic:baseImgUrl+"vipPic.png",
    hym:false,
    greyshow:false,
  },

  // 切换导航
  choseNav:function(e){
    var that = this;
    var activeIndex=e.currentTarget.dataset.index;
     
      that.setData({
        activeIndex:activeIndex
      })
  },

  //选择套餐
  choseList:function(e){
    console.log(e);
    var that = this;
    var activeIndex2 = e.currentTarget.dataset.subindex;
    that.setData({
      activeIndex2: activeIndex2
    })
  },

  //点击显示会员吗
  showhym:function(){
    var that=this;
    that.setData({
      greyshow:true
    })
  },
  //点击隐藏会员码
  hidegery: function () {
    var that = this;
    that.setData({
      greyshow: false
    })
  },
  //点击确定，表单验证
  formSubmit: function (e) {
    var that=this;
    var input_hym=e.detail.value.input;


    //请求接口，验证
    wx.request({
      url: jumpurl + 'my/yanzheng_vipma',
      data: {
        openid: app.globalData.openid,
        hma: input_hym,
        shopid: app.globalData.shopid,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data.start == 1) {
          that.setData({
            greyshow: false,
          })
          wx.showToast({
            title: '开通成功',
          })
          setTimeout(function () {
            wx.reLaunch({
              url: '/pages/mine/mine',  //地址不对
            })
          }, 1000)
        } else {
          wx.showToast({
            title: '请输入正确的验证码',
          })
        }
      },
    })
  },
  /********微信开通****** */
  kaitong_wx:function(e){
    var that=this;
    var activeIndex2=that.data.activeIndex2;
    console.log(activeIndex2);
    console.log("微信开通");
  },

  /********会员码开通****** */
  kaitong_hym: function () {
    var that = this;
    var activeIndex2 = that.data.activeIndex2;
    console.log(activeIndex2);
    console.log("会员码开通")

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.request({
      url: jumpurl + 'price/index',
      data: {
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res);
        var article = res.data.content;
        WxParse.wxParse('article', 'html', article, that, 5);
        that.setData({
          lists: res.data.lists,
          notice: res.data.notice,
        });
      },
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})